﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using WF.Common;
using SourceCode.Workflow.Client;

namespace WF.Web.Pages.WorkflowInfo
{
    public partial class ViewFlow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string verNo = Assembly.Load("WF.Web").GetName().Version.ToString(); ;
            Page.Title = "WF V" + verNo;

            int id = 0;
            if (Request.QueryString.Get("ProcInstID") == null)
            {
                throw new BusinessException("无效的参数ProcInstID!");
            }
            else
            {
                if (!IsPostBack)
                {
                    id = int.Parse(Request.QueryString.Get("ProcInstID"));
                    DisplayFlowImage(id);
                }
            }
        }

        private void DisplayFlowImage(int id)
        {
            Response.Clear();
            Response.ContentType = "image/JPEG";
            Connection oK2Connection = WF.Common.WorkFlowHelper.GetK2Connection();
            try
            {
                ViewProcessInstance.ViewImage vcp = new ViewProcessInstance.ViewImage();

                string xml;
                xml = oK2Connection.ViewProcessInstance(id);
                vcp.ViewProcess();
                vcp.Xml = xml;
                vcp.SaveImage(Response.OutputStream, 0, 0, "jpg");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString() + "<br>" + System.Environment.NewLine + ex.StackTrace.ToString());
            }
            finally
            {
                oK2Connection.Close();
            }
        }
    }
}